﻿using FormInputProject.Models;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;

namespace FormInputProject.Services
{
    public class UserBaseService
    {
        FormInputContext context = new FormInputContext();

        private readonly IUserRepository userRepository;

        public UserBaseService()
        {
            userRepository = new UserRepository();
        }

        /// <summary>
        /// 
        /// </summary>
        /// <param name="user"></param>
        /// <returns>-1:none user;0:pwd error;1 login succeed</returns>
        public int UserLogin(User user)
        {
            var query = from User u in userRepository.All
                        where u.UserName == user.UserName
                        select u;
            if (query.Count() > 0)
            {
                User dbUser = query.First();
                if (user.UserPwd == dbUser.UserPwd)
                {
                    return 1;
                }
                else
                {
                    return 0;
                }
            }

            return -1;
        }
    }
}